import { Body, Controller, Delete, Get, Patch, Post, Query, UseGuards } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import {
  AddFriendDto,
  DeleteFriendDto,
  HandleFriendRequestDto,
  UpdateFriendGroupDto,
} from '../dto/friend.dto'
import { FriendService } from '../services/friend.service'

@Controller('friends')
@UseGuards(AuthGuard('jwt'))
export class FriendController {
  constructor(private readonly friendService: FriendService) {}

  @Post()
  async addFriend(@Body() addFriendDto: AddFriendDto) {
    return this.friendService.addFriend(addFriendDto)
  }

  @Patch('request')
  async handleFriendRequest(@Body() handleFriendRequestDto: HandleFriendRequestDto) {
    return this.friendService.handleFriendRequest(handleFriendRequestDto)
  }

  @Patch('group')
  async updateFriendGroup(@Body() updateFriendGroupDto: UpdateFriendGroupDto) {
    return this.friendService.updateFriendGroup(updateFriendGroupDto)
  }

  @Delete()
  async deleteFriend(@Body() deleteFriendDto: DeleteFriendDto) {
    return this.friendService.deleteFriend(deleteFriendDto)
  }

  @Get()
  async getFriends(@Query('page') page: number = 1, @Query('limit') limit: number = 10) {
    return this.friendService.getFriends(page, limit)
  }

  @Get('requests')
  async getFriendRequests() {
    return this.friendService.getFriendRequests()
  }

  @Get('search')
  async searchFriends(@Query('keyword') keyword: string) {
    return this.friendService.searchFriends(keyword)
  }
}
